module PcatesHelper
  def pcate_options(pcates = Pcate.find(:all,:conditions =>['parent_id is null']))
    options =Array.new
    for pcate in pcates
      create_pcate_options(pcate,options)
    end
    return options
  end

  def create_pcate_options(pcate,options)
    optioin_item =Array.new
    optioin_item[1]= pcate.id.to_s
    optioin_item[0]= pcate.name
    options << optioin_item
    if pcate.children.length > 0
      pcate.children.each do |c|
        create_pcate_options(c,options)
      end
    end
  end
end
